<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Team;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;

class TeamController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Team(), function (Grid $grid) {
            $grid->column('name')->editable();
            /*$grid->column('picture')->display(function ($pictures) {
                return $pictures;
            })->image('', 50, 'auto');
            $grid->column('environment_pictures','環境圖片')->display(function ($pictures) {
                return $pictures;
            })->image('', 50, 'auto');*/
            $grid->column('status')->switch();
            $grid->column('sort')->orderable();
            $grid->column('created_at');
            $grid->quickSearch('name')->placeholder('搜索...');
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Team(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('summary');
            $show->field('detail');
            $show->field('environment');
            $show->field('picture');
            $show->field('status');
            $show->field('sort');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {



        return Form::make(new Team(), function (Form $form) {
            $form->block(6, function (Form\BlockForm $form) {
                // 设置标题
                $form->title('環境介紹');



                $form->text('name');
                $form->image('cover','封面圖')->autoUpload()->uniqueName()->move('teams');

                $form->textarea('desc','简介');

                $form->multipleImage('banners','banner')->autoUpload()->uniqueName()->move('teams')->saving(function ($banner){
                    return $banner;
                });
                $form->radio('status')->options(['1'=>'正常','0'=>'關閉'])->default(1);

                $form->multipleImage('environment_pictures','環境圖片')->move('teams')->autoUpload()->uniqueName()->sortable()->saving(function ($paths) {
                    return json_encode($paths);
                });

                $form->weditor('environment','環境介紹')->help('{LINE_ID}调用的是客服配置中的Line ID，{LINE_QRCODE}LINE二维码，{PHONE}电话，{NAME}客服名称');


            });
            $form->block(6, function (Form\BlockForm $form) {
                $form->title('班表内容');

                $form->multipleImage('picture','班表圖片')->move('teams')->autoUpload()->uniqueName()->sortable()->saving(function ($paths) {
                    return json_encode($paths);
                });
                $form->weditor('summary','班表説明');
                $form->weditor('detail','詳細内容')->help('{LINE_ID}调用的是客服配置中的Line ID，{LINE_QRCODE}LINE二维码，{PHONE}电话，{NAME}客服名称');
                // 显示底部提交按钮
                $form->showFooter();
            });


            $form->saved(function(){
                Cache::forget(config('global.cache.team'));
            });

        });
    }
}
